package 临时工具;


import lombok.Data;

import java.io.OutputStream;
import java.io.Serializable;
import java.net.HttpURLConnection;
import java.net.URL;

/**
 * 若依批量添加测试用户
 */
@Data
public class 若依批量添加测试用户 implements Serializable {
    private static String authorization="Bearer eyJhbGciOiJIUzUxMiJ9.eyJ1c2VyX2lkIjoxLCJ1c2VyX2tleSI6ImM1OGFlNjNmLWNkZGItNGM5OC1iM2Y5LWEwNzVmZTBhNTkzZCIsInVzZXJuYW1lIjoiYWRtaW4ifQ.51FJ3cy3wF5dUkq0t2b5x0Aw_g1_Y-Z6mNrczHAajhcf2tXc6AOsei-DTm35PN8a9UsVYw3o6kh4b80Rx_qx9w";
    private static String api="http://shangyu-test.xqls.tech/prod-api/system/user";
    public static void main(String[] args) {
        for (int i = 3; i <= 100; i++) {
            //格式化3位输出i
            System.out.println(String.format("%03d", i));
            addUser(String.format("%03d", i));
        }
    }
    public static void addUser(String number){
        try {
            URL url = new URL(api);
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            conn.setRequestProperty("Authorization", authorization);
            conn.setRequestMethod("POST");
            conn.setDoOutput(true);
            conn.setRequestProperty("Content-Type", "application/json");

            // 请求体
            String jsonInputString = "{\"deptId\":\"185\",\"userName\":\"test"+number+"\",\"nickName\":\"测试"+number+"\",\"password\":\"123456\",\"status\":\"0\",\"postIds\":[],\"roleIds\":[\"31\",\"2\",\"3\"]}";

            try (OutputStream os = conn.getOutputStream()) {
                byte[] input = jsonInputString.getBytes("utf-8");
                os.write(input, 0, input.length);
            }

            int code = conn.getResponseCode();
            System.out.println("响应码: " + code);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


}
